package com.hb.trade.api.routine.controller.flow;

import com.hb.core.pojo.flow.dto.FlowTempMainDTO;
import com.hb.trade.client.flow.FlowClient;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.fzzn.core.auth.shiro.util.ShiroUtil;
import org.fzzn.core.model.msg.Message;
import org.fzzn.core.model.msg.ResponseDto;
import org.fzzn.core.model.user.login.LoginUser;
import org.fzzn.core.util.ResultUtil;
import org.fzzn.core.web.anno.Version;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

@RestController
@Slf4j
@Version(1.0)
@Api(tags = {"工作流 - 流程模板"})
@RequestMapping("/{version}")
public class ApiFlowTempController {

    protected final FlowClient flowClient;

    public ApiFlowTempController(FlowClient flowClient) {
        this.flowClient = flowClient;
    }

    @ApiOperation(value = "定义流程模板", notes = "定义流程模板", httpMethod = "POST")
    @PostMapping("/flow/temp/definition")
    public ResponseDto definition(@RequestBody FlowTempMainDTO flowTempMainDto) {
        // 当前登录用户
        LoginUser<Long> currentUser = ShiroUtil.getUserEntity();
        flowTempMainDto.setCreateId(currentUser.getId());
        flowTempMainDto.setCreateName(currentUser.getUsername());
        // 保存流程模板
        Message msg = flowClient.definition(flowTempMainDto);
        return ResultUtil.msg(msg);
    }

    @ApiOperation(value = "查看流程模板详情", notes = "查看流程模板详情", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "流程模板ID", dataTypeClass = Long.class, required = true)
    })
    @PostMapping("/flow/temp/detail")
    public ResponseDto detail(@ApiIgnore @RequestBody FlowTempMainDTO flowTempMainDto) {
        // 保存流程模板
        Message<FlowTempMainDTO> msg = flowClient.detail(flowTempMainDto);
        return ResultUtil.msg(msg);
    }

}
